//package com.wxy.demo.config;
//
//import com.fasterxml.jackson.annotation.JsonInclude;
//import com.fasterxml.jackson.databind.DeserializationFeature;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.SerializationFeature;
//import com.fasterxml.jackson.databind.SerializerProvider;
//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.key.Jsr310NullKeySerializer;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//import java.text.SimpleDateFormat;
//import java.time.LocalDateTime;
//import java.time.ZoneId;
//import java.time.format.DateTimeFormatter;
//import java.util.List;
//import java.util.TimeZone;
//
////@Configuration
//public class MessageConverterConfig implements WebMvcConfigurer {
//
//    @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
//    private String pattern;
//
//    @Value("${spring.jackson.time-zone:GMT+8}")
//    private String timeZone;
//
//    /**
//     * 时间处理
//     * 使用此方法, 以下 spring-boot: jackson时间格式化 配置 将会失效
//     * spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
//     * spring.jackson.time-zone=GMT+8
//     * 原因: 会覆盖 @EnableAutoConfiguration 关于 WebMvcAutoConfiguration 的配置
//     */
//    @Override
//    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//        System.out.println("123");
//        OvsHttpMessageConverter converter = new OvsHttpMessageConverter();
//        // localDateTime格式化
//        JavaTimeModule module = new JavaTimeModule();
//        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
//        dateTimeFormatter.withZone(ZoneId.of(timeZone));
//        LocalDateTimeDeserializer dateTimeDeserializer = new LocalDateTimeDeserializer(dateTimeFormatter);
//        LocalDateTimeSerializer dateTimeSerializer = new LocalDateTimeSerializer(dateTimeFormatter);
//        module.addDeserializer(LocalDateTime.class, dateTimeDeserializer);
//        module.addSerializer(LocalDateTime.class, dateTimeSerializer);
//        ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(module)
//                .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).build();
//        // date时间格式化
//        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
//        simpleDateFormat.setTimeZone(TimeZone.getTimeZone(ZoneId.of(timeZone)));
//        objectMapper.setDateFormat(simpleDateFormat);
//        // 处理key是null
//        objectMapper.getSerializerProvider().setNullKeySerializer(new Jsr310NullKeySerializer());
//        // 处理value是null
//        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
//        converter.setObjectMapper(objectMapper);
//        converters.add(0, converter);
//
//    }
//}